<template>
	<view>
		<u-navbar back-icon-color="#fff"  title-color="#fff"  :border-bottom="false">
		<view slot="content" class="detailSelect">
			<view class="uni-list-cell-db" @click="show=!show">
				<view class="uni-input">{{selector.organizeName}}</view>
				<my-icon name="xiajiantou_biaotilan"></my-icon>
				<u-picker mode="selector" v-model="show" @confirm="confirm" :default-selector="[0]" range-key="organizeName" :range="organizeData">
				</u-picker>
			 </view>
		</view>
		</u-navbar>
		<my-empty  v-if="empyFalse" emptyTit="暂无数据"></my-empty>
		<my-user-li v-for="(item,index) in userList"  :key="index"  :infoNode='lastItem(item.lastTime)' :infoName='item.userName' :thumbnail='item.avatar' @click.native="linkDeatil(item.userId)" ></my-user-li>
		<u-loadmore v-if="userList.length!=0" icon-type="flower" bg-color="#FFFFFF" :status="status" @loadmore="getList()" :margin-top="20" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				organizeData:[],//班级数据
			  selector:{},//选中的数据
				show:false,//下拉显示
				userList:[],//练习情况
				pageNo: 1,//当前页数
				isLastPage: false,//是否最后一页
				status: 'loadmore',
				empyFalse:false
			}
		},
		onLoad(){
			this.getOragnize()
			this.init()
		},
		computed:{
			lastItem(){
			  return function (value) {
					 if(value){
						return  '最近一次练习：'+value
					 }
			     
			  }
			}
		},
		methods: {
			init(){
				this.status = 'loadmore';
				this.pageNo=1;
				this.isLastPage=false;
				this.userList=[];//练习情况
				return this.getList();
			},
			// 获取班级
			getOragnize(){
				return new Promise((resolve, reject) => {
					this.request
						.get('/app/teacher/examanalysis/getClassCode',)
						.then(res => {
								this.organizeData=res;
								this.selector=this.organizeData[0];//默认选中第一个
								this.getList()
							resolve();
						})
						.catch(reject)
				});
			},
			linkDeatil(userId){
				//跳转详情列表
				uni.navigateTo({
					url:'practiceDetail?userId='+userId
				})
			},
			// 获取列表
			getList(){
				const pageData={'classCode':this.selector.organizeCode,'pageNo':this.pageNo};
				this.status = 'loading';
				return new Promise((resolve, reject) => {
					this.request
						.post('/app/teacher/home/getExerciseList',pageData)
						.then(res => {
							 this.userList=res.list;
							 this.empyFalse=this.userList.length>0?false:true
							 this.isLastPage =res.isLastPage;
							 if (!res.isLastPage) this.pageNo++;
							 else this.status = 'nomore';
							resolve();
						})
						.catch(reject)
				});
			},
			//确认选择
      confirm: function(e){
				this.selector=this.organizeData[e]
					this.getList()
			},
		}
	}
</script>

<style>

</style>
